package gui;

import java.util.StringTokenizer;

import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class AbstractDefensiveDriverPanel {

	protected Display display;
	protected Shell shell;
	private boolean hidden = false;
	private boolean enabled = true;

	public AbstractDefensiveDriverPanel() {
		super();
	}
	
	public AbstractDefensiveDriverPanel(Display display, Shell shell) {
		this.display = display;
		this.shell = shell;
	}

	public void hide(boolean flag) {
		Control[] children = shell.getChildren();
		if(children.length == 0) {
			System.out.println("Shell does not have any children");
		} else {
			for(int i = 0; i < children.length; i++) {
				children[i].setVisible(!flag);
			}
			shell.update();
			hidden = flag;
		}
	}

	public void dispose() {
		Control[] children = shell.getChildren();
		if(children.length == 0) {
			System.out.println("Shell does not have any children");
		} else {
			for(int i = 0; i < children.length; i++) {
				children[i].dispose();
			}
		}
	}
	
	public boolean isHidden() {
		return hidden;
	}
	
	public void setEnabled(boolean flag) {
		Control[] children = shell.getChildren();
		if(children.length == 0) {
			System.out.println("Shell does not have any children");
		} else {
			for(int i = 0; i < children.length; i++) {
				children[i].setEnabled(flag);
			}
			enabled = flag;
		}
	}
	
	public boolean isEnabled() {
		return enabled;
	}
	
	public String removeSpaces(String s) {
		String t = "";
		StringTokenizer st = new StringTokenizer(s, " ", false);
		while(st.hasMoreElements()) {
			t += st.nextElement();
		}
		return t;
	}
}